local ServerOHOH = _G.ServerOHOH;
local CommonOHOH =_G.CommonOHOH
local BigNumberHelper = CommonOHOH.load.BigNumberHelper();
local GeneralTool=_G.CommonOHOH.load.GeneralTool();
local Server_RankManager = ServerOHOH.load.Server_RankManager();
local RankCalss=require(script.Parent.Parent.RankUI)

local hour=60*60

function UpdRankData(key,value,userId)
	Server_RankManager:SetRankValue(key, userId, function()
		return GeneralTool.ShortRankNumber(value)
	end);
end

local RankList={
	sponsor=RankCalss.new(workspace.Rank:WaitForChild("sponsor")),
	rolls=RankCalss.new(workspace.Rank:WaitForChild("rolls")),
	elo=RankCalss.new(workspace.Rank:WaitForChild("elo")),
	time=RankCalss.new(workspace.Rank:WaitForChild("time")),
	challenger=RankCalss.new(workspace.Rank:WaitForChild("challenger")),
}

RankList.rolls:InitRank(function(valueLable,value,userId)
		local newValue,HadNoTag=GeneralTool.RecoverRankNumber(value)
		valueLable.Text=BigNumberHelper:ToString(newValue)
end)

RankList.time:InitRank(function(valueLable,value,userId)
		local h=math.floor(value/hour)
        valueLable.Text=h.." h"
end)

RankList.elo:InitRank(function(valueLable,value,userId)
	local newValue,HadNoTag=GeneralTool.RecoverRankNumber(value)
	valueLable.Text=BigNumberHelper:ToString(newValue)
end)

RankList.challenger:InitRank()
RankList.sponsor:InitRank()

local M = ServerOHOH.class.new(script, ServerOHOH.files.BaseComponent());

function M.new(self,...)
	return M(self,...);
end;


function M.ctor(self, parent)
	M.super.ctor(self, parent);
	self.data={}

  self.UpdUiCon= _G.server:GetComponent(ServerOHOH.load.Server_RankComponent()).UpdataRankDataEvent:Connect(function(rankData)
            if rankData then
				for k,v in pairs(rankData) do
					if RankList[k] then
						RankList[k]:Update(v)
					end
				end
			end
    end)
end;

function M.dtor(self)
    self.UpdUiCon:Disconnect()
	M.super.dtor(self);
end;



return M;

